function createSlice({ name, initialState, reducers }) {
  // 生成 action creators
  const actionCreators = {};
  for (let actionType in reducers) {
    actionCreators[actionType] = (payload) => ({ type: `${name}/${actionType}`, payload });
  }

  // 生成 reducer
  const reducer = (state = initialState, action) => {
    const reducerFunction = reducers[action.type.split('/')[1]];
    if (reducerFunction) {
      return reducerFunction(state, action);
    }
    return state;
  };

  // 返回 action creators 和 reducer
  return {
    actions: actionCreators,
    reducer: reducer
  };
}